package com.richman.hgps38;

import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.Vector;
import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;

import com.richman.controller.DecreseRatio;
import com.richman.ps38.entity.Event;
import com.richman.ps38.entity.HGEvent;
import com.richman.ps38.entity.HGISNEvent;
import com.richman.ps38.entity.ISNPS38Event;
import com.richman.ps38.entity.ISNEvent;
import com.richman.ps38.entity.ISNHGSendData;
import com.richman.ps38.entity.SendData;
import com.richman.utils.Common;

public class ISNPS38EventManager {
	
	private  ReadWriteLock hgeventsLock = new ReentrantReadWriteLock();
	private  Vector<HGEvent>  hgevents= new Vector<HGEvent>();

	private  ReadWriteLock ps38eventsLock = new ReentrantReadWriteLock();
	private  Vector<Event> ps38events = new 	Vector<Event>();
	

	
	private  ReadWriteLock isnps38eventsLock = new ReentrantReadWriteLock();
	private  Vector<ISNPS38Event> isnps38events = new Vector<ISNPS38Event>(); 
	
	
	
	private  ReadWriteLock senddataLock = new ReentrantReadWriteLock(); 
	private  Vector<SendData> senddatas = new Vector<SendData>();
	
	
	//ISN&HG
	private  ReadWriteLock isneventsLock = new ReentrantReadWriteLock();
	private  Vector<ISNEvent>  isnevents= new Vector<ISNEvent>();
	
	private  ReadWriteLock isnhgsenddataLock = new ReentrantReadWriteLock();
	private  Vector<ISNHGSendData> isnhgsenddatas = new Vector<ISNHGSendData>();
	
	private  ReadWriteLock hgisneventsLock = new ReentrantReadWriteLock();
	private  Vector<HGISNEvent> hgisnevents = new Vector<HGISNEvent>(); 
	
	public void updatehgevents(Vector<HGEvent> hg) {
		
		
		try {
			
			hgeventsLock.writeLock().lock();
			
			hgevents.clear();
			
			for(int i = 0; i < hg.size(); i++) {
				hgevents.add(hg.elementAt(i));
			}
			
			
			
			
		}catch(Exception e) {
			e.printStackTrace();
		}

		hgeventsLock.writeLock().unlock();
		
	}
	
	public Vector<HGEvent> gethgvents() {
		
		try {
			
			hgeventsLock.readLock().lock();
			
			Vector<HGEvent> hgeventsTmp = new Vector<HGEvent>();
			
			for(int i = 0; i < hgevents.size(); i++) {
				hgeventsTmp.add(hgevents.elementAt(i));
			}
			
			hgeventsLock.readLock().unlock();
			
			return hgeventsTmp;
			
		}catch(Exception e) {
			e.printStackTrace();
			
			hgeventsLock.readLock().unlock();
			
		}
		
		return null;
		
		
		
	}
	
	
	public void updateps38events(Vector<Event> ps38) {
		
		
		try {
			
			ps38eventsLock.writeLock().lock();
			
			ps38events.clear();
			
			for(int i = 0; i < ps38.size(); i++) {
				ps38events.add(ps38.elementAt(i));
			}
			
			
			
			
		}catch(Exception e) {
			e.printStackTrace();
		}

		ps38eventsLock.writeLock().unlock();
		
	}
	
	public Vector<Event> getps38vents() {
		
		try {
			
			ps38eventsLock.readLock().lock();
			
			Vector<Event> ps38eventsTmp = new Vector<Event>();
			
			for(int i = 0; i < ps38events.size(); i++) {
				ps38eventsTmp.add(ps38events.elementAt(i));
			}
			
			ps38eventsLock.readLock().unlock();
			
			return ps38eventsTmp;
			
		}catch(Exception e) {
			e.printStackTrace();
			
			ps38eventsLock.readLock().unlock();
			
		}
		
		return null;
		
		
		
	}
	
	
	public void updateisnevents(Vector<ISNEvent> isn) {
		
		
		try {
			
			isneventsLock.writeLock().lock();
			
			isnevents.clear();
			
			for(int i = 0; i < isn.size(); i++) {
				isnevents.add(isn.elementAt(i));
			}
			
			
			
			
		}catch(Exception e) {
			e.printStackTrace();
		}

		isneventsLock.writeLock().unlock();
		
	}
	
	public Vector<ISNEvent> getisnvents() {
		
		try {
			
			isneventsLock.readLock().lock();
			
			Vector<ISNEvent> isneventsTmp = new Vector<ISNEvent>();
			
			for(int i = 0; i < isnevents.size(); i++) {
				isneventsTmp.add(isnevents.elementAt(i));
			}			
			isneventsLock.readLock().unlock();			
			return isneventsTmp;
			
		}catch(Exception e) {
			e.printStackTrace();			
			hgeventsLock.readLock().unlock();			
		}		
		return null;
		
	}
	
	
	
	
	
	public void constructisnps38events() {
		
		try {
			isnps38eventsLock.writeLock().lock();
			
			isneventsLock.readLock().lock();
			ps38eventsLock.readLock().lock();
			senddataLock.writeLock().lock();

			isnps38events.clear();
			senddatas.clear();
			
			Vector<String[]> isnps38teams = DecreseRatio.mainWnd.getISNPS38TeamsList();
			Vector<String[]> isnps38leagues = DecreseRatio.mainWnd.getISNPS38LeaguesList();
			
			Vector<String[]> hgps38teams = DecreseRatio.mainWnd.getHGPS38TeamsList();
			Vector<String[]> hgps38leagues = DecreseRatio.mainWnd.getHGPS38LeaguesList();
			
			for(int i = 0; i < hgevents.size(); i++) {
				HGEvent hgeventtmp = hgevents.elementAt(i);
				//根据皇冠队   找到PS38队名
				String ps38league = "";
				String ps38hometeam = "";
				String ps38awayteam = "";
				for(int j = 0; j < hgps38leagues.size(); j++) {
					if(hgps38leagues.elementAt(j)[0].equals(hgeventtmp.leagueName)) {
						ps38league = hgps38leagues.elementAt(j)[1];
						break;
					}
				}
				
				if(!ps38league.equals("")) {
					for(int j = 0; j < hgps38teams.size(); j++) {
						if(hgps38teams.elementAt(j)[0].equals(hgeventtmp.homeTeam)) {
							ps38hometeam = hgps38teams.elementAt(j)[1];
							break;
						}
					}
					
					if(!ps38hometeam.equals("")) {
						for(int j = 0; j < hgps38teams.size(); j++) {
							if(hgps38teams.elementAt(j)[0].equals(hgeventtmp.awayTeam)) {
								ps38awayteam = hgps38teams.elementAt(j)[1];
								break;
							}
						}						
					}
				}
				ISNEvent isnEventnew = new ISNEvent();
				Event ps38Eventnew = new Event();
				ISNPS38Event isnps38eventtmp = new ISNPS38Event();
				boolean add = false;
				if(!ps38hometeam.equals("")&&!ps38awayteam.equals("")) {
					for(int j = 0; j<ps38events.size(); j++) {
						Event ps38eventtmp = ps38events.elementAt(j);
						if(ps38eventtmp.homeTeam.equals(ps38hometeam)&&ps38eventtmp.awayTeam.equals(ps38awayteam)) {
							if(!hgeventtmp.wholeDXPPankou.equals("")&&!ps38eventtmp.wholeDXPPankou.equals("")
									&&( Math.abs(Double.parseDouble(hgeventtmp.wholeDXPPankou) -  Double.parseDouble(ps38eventtmp.wholeDXPPankou)) < 0.001 )) {
								add = true;
								ps38Eventnew.wholeDXPBetID = 	ps38eventtmp.wholeDXPBetID;
								ps38Eventnew.wholeDXPPankou = 	ps38eventtmp.wholeDXPPankou;
								ps38Eventnew.eventId = 			ps38eventtmp.eventId;
								ps38Eventnew.leagueName = 		ps38eventtmp.leagueName;
								ps38Eventnew.homeTeam = 		ps38eventtmp.homeTeam;
								ps38Eventnew.awayTeam = 		ps38eventtmp.awayTeam;
								isnps38eventtmp.wholeDXPPankou = hgeventtmp.wholeDXPPankou;
								isnps38eventtmp.wholeDXPPankouDown = ps38eventtmp.wholeDXPPankouUp;
							}
							
							if(!hgeventtmp.halfDXPPankou.equals("")&&!ps38eventtmp.halfDXPPankou.equals("")
									&&( Math.abs(Double.parseDouble(hgeventtmp.halfDXPPankou) -  Double.parseDouble(ps38eventtmp.halfDXPPankou)) < 0.001 )) {
								add = true;
								ps38Eventnew.halfBetID = 	ps38eventtmp.halfBetID;
								ps38Eventnew.halfDXPPankou = 	ps38eventtmp.halfDXPPankou;
								ps38Eventnew.eventId = 			ps38eventtmp.eventId;
								ps38Eventnew.leagueName = 		ps38eventtmp.leagueName;
								ps38Eventnew.homeTeam = 		ps38eventtmp.homeTeam;
								ps38Eventnew.awayTeam = 		ps38eventtmp.awayTeam;
								isnps38eventtmp.halfDXPPankou = hgeventtmp.halfDXPPankou;
								isnps38eventtmp.halfDXPPankouDown = ps38eventtmp.halfDXPPankouUp;
							}
						}
					}
					
					
					
					String isnhometeam = "";
					String isnawayteam = "";
					//找到ISN球赛
					String isnleague = "";
					for(int j = 0; j < isnps38leagues.size(); j++) {
						if(isnps38leagues.elementAt(j)[1].equals(ps38league)) {
							isnleague = isnps38leagues.elementAt(j)[0];
							break;
						}
					}
					
					if(!isnleague.equals("")) {
						for(int j = 0; j < isnps38teams.size(); j++) {
							if(isnps38teams.elementAt(j)[1].equals(ps38hometeam)) {
								isnhometeam = isnps38teams.elementAt(j)[0];
								break;
							}
						}
						
						if(!isnhometeam.equals("")) {						
							for(int j = 0; j < isnps38teams.size(); j++) {
								if(isnps38teams.elementAt(j)[1].equals(ps38awayteam)) {
									isnawayteam = isnps38teams.elementAt(j)[0];
									break;
								}
							}						
						}
					}
					
					
					if(!isnhometeam.equals("")&&!isnawayteam.equals("")) {
						for(int j = 0; j<isnevents.size();j++) {
							ISNEvent isneventtmp = isnevents.elementAt(j);
							if(isneventtmp.homeTeam.equals(isnhometeam)&&isneventtmp.awayTeam.equals(isnawayteam)) {
								if(!hgeventtmp.wholeDXPPankou.equals("")&&!isneventtmp.wholeDXPPankou.equals("")
										&&( Math.abs(Double.parseDouble(hgeventtmp.wholeDXPPankou) -  Double.parseDouble(isneventtmp.wholeDXPPankou)) < 0.001 )) {
									add = true;	
									isnEventnew.leagueName = isneventtmp.leagueName;
									isnEventnew.homeTeam = isneventtmp.homeTeam;
									isnEventnew.awayTeam = isneventtmp.awayTeam;
									isnEventnew.eventTime = isneventtmp.eventTime;	
									isnEventnew.duringTime = isneventtmp.duringTime;
									isnEventnew.wholeDXPPankou = 	isneventtmp.wholeDXPPankou;
									isnEventnew.wholeDXPPankouUp = 	isneventtmp.wholeDXPPankouUp;
									
									isnps38eventtmp.wholeDXPPankou = hgeventtmp.wholeDXPPankou;
									isnps38eventtmp.wholeDXPPankouUp = isneventtmp.wholeDXPPankouUp;
								}
								
								if(!hgeventtmp.halfDXPPankou.equals("")&&!isneventtmp.halfDXPPankou.equals("")
										&&( Math.abs(Double.parseDouble(hgeventtmp.halfDXPPankou) -  Double.parseDouble(isneventtmp.halfDXPPankou)) < 0.001 )) {
									add = true;
									isnEventnew.leagueName = isneventtmp.leagueName;
									isnEventnew.homeTeam = isneventtmp.homeTeam;
									isnEventnew.awayTeam = isneventtmp.awayTeam;
									isnEventnew.eventTime = isneventtmp.eventTime;	
									isnEventnew.duringTime = isneventtmp.duringTime;
									isnEventnew.halfDXPPankou = 	isneventtmp.halfDXPPankou;
									isnEventnew.halfDXPPankouUp = 	isneventtmp.halfDXPPankouUp;
									
									isnps38eventtmp.halfDXPPankou = hgeventtmp.halfDXPPankou;
									isnps38eventtmp.halfDXPPankouUp = isneventtmp.halfDXPPankouUp;
								}
							}
							
						}
					}
					
				}
				
				
				if(add) {
					
					isnps38eventtmp.leagueName = hgeventtmp.leagueName;
					isnps38eventtmp.homeTeam = hgeventtmp.homeTeam;
					isnps38eventtmp.awayTeam = hgeventtmp.awayTeam;
					isnps38eventtmp.eventTime = hgeventtmp.eventTime;
					isnps38eventtmp.duringTime = hgeventtmp.duringTime;
					isnps38eventtmp.homeTeamScore = hgeventtmp.homeTeamScore;
					isnps38eventtmp.awayTeamScore = hgeventtmp.awayTeamScore;

					isnps38events.add(isnps38eventtmp);
					
					SendData senddata = new SendData();
					senddata.isnevent = isnEventnew;
					senddata.event = ps38Eventnew;
					senddata.isnps38event = isnps38eventtmp;
					
					senddatas.add(senddata);
					
				}
				
			}

			
			
			
			DecreseRatio.mainWnd.updateHGPS38EventsTable(isnps38events);

				
		}catch(Exception e) {
			e.printStackTrace();
		}
		
		isnps38eventsLock.writeLock().unlock();
		isneventsLock.readLock().unlock();
		ps38eventsLock.readLock().unlock();
		
		senddataLock.writeLock().unlock();
	}
	
	

	public void constructisnhgevents() {
		
		try {
			//isnhgeventsLock.writeLock().lock();
			
			hgeventsLock.readLock().lock();			
			isnhgsenddataLock.writeLock().lock();
			hgisneventsLock.writeLock().lock();
			isneventsLock.readLock().lock();			

			isnhgsenddatas.clear();
			
			
			ISNEvent justavoiderror = null;
			
			Vector<String[]> hgisnteams = DecreseRatio.mainWnd.getHGISNTeamsList();
//			Vector<String[]> hgps38teams = DaShui.mainWnd.getHGPS38TeamsList();
//			Vector<String[]> hgps38leagues = DaShui.mainWnd.getHGPS38LeaguesList();
			
			
			double sideMinodd = DecreseRatio.mainWnd.getsideMinodd();
			double sumMinodd = DecreseRatio.mainWnd.getsumMinodd();
			
			double sideMaxodd = DecreseRatio.mainWnd.getsideMaxodd();
			double sumMaxodd = DecreseRatio.mainWnd.getsumMaxodd();
			
			
			for(int i = 0; i < hgevents.size(); i++) {				
				String isnhometeam = "";
				String isnawayteam = "";				
				HGEvent hgeventtmp = hgevents.elementAt(i);		
				//根据hgevent的team 找到isn对应的team
				for(String[] team: hgisnteams) {

					if(isnhometeam.equals("") && team[0].equals(hgeventtmp.homeTeam)) {
						isnhometeam = team[1];
					}
					
					if(isnawayteam.equals("") && team[0].equals(hgeventtmp.awayTeam)) {
						isnawayteam = team[1];
					}
					
					if(!isnhometeam.equals("") && !isnawayteam.equals("")) {
						break;
					}
				}//
				

				
				if(!isnhometeam.equals("") && !isnawayteam.equals("")) {//如果找到ISN球队
					

					
					for(int j = 0; j < isnevents.size(); j++) {
						
						if((isnevents.elementAt(j).homeTeam + "-vs-" + isnevents.elementAt(j).awayTeam).equals(isnhometeam + "-vs-" + isnawayteam)) {
							
							HGISNEvent hgisneventtmp = new HGISNEvent();
							//比较盘口，大小盘
							
							boolean add = false;
							
							ISNEvent isneventtmp = isnevents.elementAt(j);
							
							
							//全场
							//if(hgeventtmp.wholerqppankou.equals(ps38eventtmp.wholerqppankou)) {
							if(!hgeventtmp.wholeRQPPankou.equals("") && !isneventtmp.wholeRQPPankou.equals("") && ( Math.abs(Double.parseDouble(hgeventtmp.wholeRQPPankou) -  Double.parseDouble(isneventtmp.wholeRQPPankou)) < 0.001 )) {
								
								
								
								//hg主赔 + ps38客赔
								
								if(!hgeventtmp.wholeRQPPankouUp.equals("") && !isneventtmp.wholeRQPPankouDown.equals("")) {
									//hgps38eventtmp.wholeRQPPankouUp = Double.toString(Double.parseDouble(hgeventtmp.wholeRQPPankouUp) + Double.parseDouble(ps38eventtmp.wholeRQPPankouDown));

									double hgodd = Double.parseDouble(hgeventtmp.wholeRQPPankouUp);
									double isnodd = Double.parseDouble(isneventtmp.wholeRQPPankouDown);
									
									DecimalFormat df = new DecimalFormat("#.000");
									
									if(isnodd < 0.0) {
										isnodd = Double.parseDouble(df.format(2.0 + isnodd));
									}
									
									if(hgodd >= sideMinodd && isnodd >= sideMinodd && (hgodd + isnodd) >= sumMinodd && hgodd <= sideMaxodd && isnodd <= sideMaxodd && (hgodd+isnodd) <= sumMaxodd) {
										
										if(isIntime("全场", justavoiderror)) {
										hgisneventtmp.wholerqppankou = hgeventtmp.wholeRQPPankou;
										
										hgisneventtmp.wholeRQPPankouUp = String.format("%.3f",hgodd + isnodd);
										
										
										add = true;
										}
										
										
									}
									

								}
								

								//hg客队 +ps38主赔
								if(!hgeventtmp.wholeRQPPankouDown.equals("") && !isneventtmp.wholeRQPPankouUp.equals("")) {
									
									double hgodd = Double.parseDouble(hgeventtmp.wholeRQPPankouDown);
									double ps38odd = Double.parseDouble(isneventtmp.wholeRQPPankouUp);
									
									DecimalFormat df = new DecimalFormat("#.000");
									
									if(ps38odd < 0.0) {
										ps38odd = Double.parseDouble(df.format(2.0 + ps38odd));
									}
									
									if(hgodd >= sideMinodd && ps38odd >= sideMinodd && (hgodd + ps38odd) >= sumMinodd&& hgodd <= sideMaxodd && ps38odd <= sideMaxodd && (hgodd+ps38odd) <= sumMaxodd) {
										
										if(isIntime("全场", justavoiderror)) {
										hgisneventtmp.wholerqppankou = hgeventtmp.wholeRQPPankou;
										hgisneventtmp.wholeRQPPankouDown = String.format("%.3f",hgodd + ps38odd);
										
											add = true;
										}
									}
									
									
								}

							}
							
							
							//if(hgeventtmp.wholeDXPPankou.equals(ps38eventtmp.wholeDXPPankou)) {
							if(!hgeventtmp.wholeDXPPankou.equals("") && !isneventtmp.wholeDXPPankou.equals("") && ( Math.abs(Double.parseDouble(hgeventtmp.wholeDXPPankou) -  Double.parseDouble(isneventtmp.wholeDXPPankou)) < 0.001 )) {	
								
								//hg大赔 + ps38小赔
								
								
								
								if(!hgeventtmp.wholeDXPPankouUp.equals("") && !isneventtmp.wholeDXPPankouDown.equals("")) {
									
									double hgodd = Double.parseDouble(hgeventtmp.wholeDXPPankouUp);
									double ps38odd = Double.parseDouble(isneventtmp.wholeDXPPankouDown);
									
									DecimalFormat df = new DecimalFormat("#.000");
									
									if(ps38odd < 0.0) {
										ps38odd = Double.parseDouble(df.format(2.0 + ps38odd));
									}
									
									if(hgodd >= sideMinodd && ps38odd >= sideMinodd && (hgodd + ps38odd) >= sumMinodd&& hgodd <= sideMaxodd && ps38odd <= sideMaxodd && (hgodd+ps38odd) <= sumMaxodd) {
										
										if(isIntime("全场", justavoiderror)) {
										hgisneventtmp.wholeDXPPankou = hgeventtmp.wholeDXPPankou;
										hgisneventtmp.wholeDXPPankouUp = String.format("%.3f",hgodd + ps38odd);
										
											add = true;
										}
									}
									

								}
								
								
								//hg小赔 +ps38大赔
								
								if(!hgeventtmp.wholeDXPPankouDown.equals("") && !isneventtmp.wholeDXPPankouUp.equals("")) {
									
									double hgodd = Double.parseDouble(hgeventtmp.wholeDXPPankouDown);
									double ps38odd = Double.parseDouble(isneventtmp.wholeDXPPankouUp);

									DecimalFormat df = new DecimalFormat("#.000");
									
									if(ps38odd < 0.0) {
										ps38odd = Double.parseDouble(df.format(2.0 + ps38odd));
									}									
									
									if(hgodd >= sideMinodd && ps38odd >= sideMinodd && (hgodd + ps38odd) >= sumMinodd&& hgodd <= sideMaxodd && ps38odd <= sideMaxodd && (hgodd+ps38odd) <= sumMaxodd) {
										
										if(isIntime("全场", justavoiderror)) {
										hgisneventtmp.wholeDXPPankou = hgeventtmp.wholeDXPPankou;
										hgisneventtmp.wholeDXPPankouDown = String.format("%.3f",hgodd + ps38odd);									
										
											add = true;
										}
									}

								}

								
							}
							

							
							
							if(add) {

								
								hgisneventtmp.leagueName = hgeventtmp.leagueName;
								hgisneventtmp.homeTeam = hgeventtmp.homeTeam;
								hgisneventtmp.awayTeam = hgeventtmp.awayTeam;
								hgisneventtmp.eventTime = hgeventtmp.eventTime;
								
								
								hgisnevents.add(hgisneventtmp);
								
								ISNHGSendData isnhgsenddata = new ISNHGSendData();
								isnhgsenddata.hgevent = hgeventtmp;
								isnhgsenddata.isnevent = isneventtmp;
								isnhgsenddata.hgisnevent = hgisneventtmp;
								
								isnhgsenddatas.add(isnhgsenddata);
								
								
									//System.out.println(hgisneventtmp.toString());
								
								
								
								
							}
							
							
							
							//break;
						}
						
					}
				}
				
				
			}
			
			
			
			
			//DaShui.mainWnd.updateHGPS38EventsTable(hgps38events);

				
		}catch(Exception e) {
			e.printStackTrace();
		}

		
		hgisneventsLock.writeLock().unlock();
		hgeventsLock.readLock().unlock();
		isneventsLock.readLock().unlock();
		
		isnhgsenddataLock.writeLock().unlock();
	}
	public void constructisnps38events_old() {
		
		try {
			isnps38eventsLock.writeLock().lock();
			
			isneventsLock.readLock().lock();
			ps38eventsLock.readLock().lock();
			senddataLock.writeLock().lock();

			isnps38events.clear();
			senddatas.clear();
			
			Vector<String[]> isnps38teams = DecreseRatio.mainWnd.getISNPS38TeamsList();
			Vector<String[]> isnps38leagues = DecreseRatio.mainWnd.getISNPS38LeaguesList();

			for(int i = 0; i < ps38events.size(); i++) {
				
				String isnhometeam = "";
				String isnawayteam = "";
				
				Event ps38eventtmp = ps38events.elementAt(i);
				
				String isnleague = "";
				for(int j = 0; j < isnps38leagues.size(); j++) {
					if(isnps38leagues.elementAt(j)[1].equals(ps38eventtmp.leagueName)) {
						isnleague = isnps38leagues.elementAt(j)[0];
						break;
					}
				}
				
				if(!isnleague.equals("")) {
					for(int j = 0; j < isnps38teams.size(); j++) {
						if(isnps38teams.elementAt(j)[1].equals(ps38eventtmp.homeTeam)) {
							isnhometeam = isnps38teams.elementAt(j)[0];
							break;
						}
					}
					
					if(!isnhometeam.equals("")) {						
						for(int j = 0; j < isnps38teams.size(); j++) {
							if(isnps38teams.elementAt(j)[1].equals(ps38eventtmp.awayTeam)) {
								isnawayteam = isnps38teams.elementAt(j)[0];
								break;
							}
						}						
					}
				}
				
				
				
				if(!isnhometeam.equals("") && !isnawayteam.equals("")) {
					for(int j = 0; j < isnevents.size(); j++) {
						
						if((isnevents.elementAt(j).homeTeam + "-vs-" + isnevents.elementAt(j).awayTeam).equals(isnhometeam + "-vs-" + isnawayteam)) {
							
							ISNPS38Event isnps38eventtmp = new ISNPS38Event();
							//比较盘口，大小盘
							
							boolean add = false;
							
							ISNEvent isneventtmp = isnevents.elementAt(j);
							
							
							//全场
							//if(hgeventtmp.wholeDXPPankou.equals(ps38eventtmp.wholeDXPPankou)) {
							if(!isneventtmp.wholeDXPPankou.equals("") && !ps38eventtmp.wholeDXPPankou.equals("") && ( Math.abs(Double.parseDouble(isneventtmp.wholeDXPPankou) -  Double.parseDouble(ps38eventtmp.wholeDXPPankou)) < 0.001 )) {	
								
								//hg大赔 + ps38小赔

								if(!isneventtmp.wholeDXPPankouUp.equals("") && !ps38eventtmp.wholeDXPPankouDown.equals("")) {
									
									double hgodd = Double.parseDouble(isneventtmp.wholeDXPPankouUp);
									double ps38odd = Double.parseDouble(ps38eventtmp.wholeDXPPankouDown);
									
									DecimalFormat df = new DecimalFormat("#.000");
									
									if(ps38odd < 0.0) {
										ps38odd = Double.parseDouble(df.format(2.0 + ps38odd));
									}
									
									isnps38eventtmp.wholeDXPPankou = isneventtmp.wholeDXPPankou;
									isnps38eventtmp.wholeDXPPankouUp = isneventtmp.wholeDXPPankouUp;	//ISN大球赔率
									isnps38eventtmp.wholeDXPPankouDown = ps38eventtmp.wholeDXPPankouUp;	//PS38大球赔率
									add = true;

								}

							}
							
							
							//半场

							//if(hgeventtmp.halfDXPPankou.equals(ps38eventtmp.halfDXPPankou)) {
							//加入add==true  优先考虑全场
							if(add == true&&!isneventtmp.halfDXPPankou.equals("") && !ps38eventtmp.halfDXPPankou.equals("") && ( Math.abs(Double.parseDouble(isneventtmp.halfDXPPankou) -  Double.parseDouble(ps38eventtmp.halfDXPPankou)) < 0.001 )) {	

								
								if(!isneventtmp.halfDXPPankouUp.equals("") && !ps38eventtmp.halfDXPPankouUp.equals("")) {
									
									double hgodd = Double.parseDouble(isneventtmp.halfDXPPankouDown);
									double ps38odd = Double.parseDouble(ps38eventtmp.halfDXPPankouUp);
									
									DecimalFormat df = new DecimalFormat("#.000");
									
									if(ps38odd < 0.0) {
										ps38odd = Double.parseDouble(df.format(2.0 + ps38odd));
									}
									
									isnps38eventtmp.halfDXPPankou = isneventtmp.halfDXPPankou;
									isnps38eventtmp.halfDXPPankouUp = isneventtmp.halfDXPPankouUp;
									isnps38eventtmp.halfDXPPankouDown = ps38eventtmp.halfDXPPankouUp;
									add = true;
									

								}

								
							}
							
							if(add==true) {
								if(isnps38eventtmp.halfDXPPankou.equals("")) {
									isnps38eventtmp.halfDXPPankou = ps38eventtmp.halfDXPPankou;
									isnps38eventtmp.halfDXPPankouDown = ps38eventtmp.halfDXPPankouUp;
								}
							}
							
							if(add) {
								
								isnps38eventtmp.leagueName = isneventtmp.leagueName;
								isnps38eventtmp.homeTeam = isneventtmp.homeTeam;
								isnps38eventtmp.awayTeam = isneventtmp.awayTeam;
								isnps38eventtmp.eventTime = isneventtmp.eventTime;
								
								
								isnps38events.add(isnps38eventtmp);
								
								SendData senddata = new SendData();
								senddata.isnevent = isneventtmp;
								senddata.event = ps38eventtmp;
								senddata.isnps38event = isnps38eventtmp;
								
								senddatas.add(senddata);
								break;
								
							}
							
							
							
							//break;
						}
						
					}
				}
				
				
			}
			
			
			
			DecreseRatio.mainWnd.updateHGPS38EventsTable(isnps38events);

				
		}catch(Exception e) {
			e.printStackTrace();
		}
		
		isnps38eventsLock.writeLock().unlock();
		isneventsLock.readLock().unlock();
		ps38eventsLock.readLock().unlock();
		
		senddataLock.writeLock().unlock();
	}

	
	
	public Vector<SendData> getsenddatas() {
		
		
		Vector<SendData> vec = new Vector<SendData>();
		
		senddataLock.readLock().lock();
		
		
		
		for(int i = 0; i < senddatas.size(); i++){
		
			
			
			
			vec.add(senddatas.elementAt(i));
			

			
		}
		
		senddataLock.readLock().unlock();
		
		return vec;
		
		
		
	}
	
	
	public Vector<ISNHGSendData> getisnhgsenddatas() {
		
		Vector<ISNHGSendData> vec = new Vector<ISNHGSendData>();
		isnhgsenddataLock.readLock().lock();
		for(int i = 0; i < isnhgsenddatas.size(); i++){
			vec.add(isnhgsenddatas.elementAt(i));
		}		
		isnhgsenddataLock.readLock().unlock();
		return vec;
	}
	
	
	public boolean isIntime(String type, ISNEvent isnevent) {
		
		try {
			
			
			
			int danshiMinTime = DecreseRatio.mainWnd.getDanshiMinTime();
			int danshiMaxTime = DecreseRatio.mainWnd.getDanshiMaxTime();
			int gqHalfMinTime = DecreseRatio.mainWnd.getGqHalfMinTime();
			int gqHalfMaxTime = DecreseRatio.mainWnd.getGqHalfMaxTime();
			int gqWholeMinTime = DecreseRatio.mainWnd.getGqWholeMinTime();
			int gqWholeMaxTime = DecreseRatio.mainWnd.getGqWholeMaxTime();
			
			SimpleDateFormat dfmin = new SimpleDateFormat("yyyy-MM-dd HH:mm");
			
			
			if(type.contains("全场")) {
				if(isnevent.duringTime.equals("")) {//单式
					Long eventtime = dfmin.parse(isnevent.eventTime).getTime();
					
					if(eventtime - System.currentTimeMillis() > danshiMaxTime*60*1000 || eventtime - System.currentTimeMillis() < danshiMinTime*60*1000) {
						return false;
					}
					
					return true;
				}else {
					
					int currentmin = 0;
							
					if(isnevent.duringTime.contains("半场")) {
						currentmin = 45;
					}else if(isnevent.duringTime.contains("1H")) {
						String str = isnevent.duringTime.replace("1H", "");
						str = str.replace(" ", "");
						currentmin = Integer.parseInt(str.split(":")[0]);
					}else if(isnevent.duringTime.contains("2H")) {
						String str = isnevent.duringTime.replace("2H", "");
						str = str.replace(" ", "");
						currentmin = Integer.parseInt(str.split(":")[0])+ 45;
					}
					
					if(currentmin > gqWholeMaxTime || currentmin < gqWholeMinTime) {
						return false;
					}
							
					return true;
				}
			}else if(type.contains("半场")) {
				if(isnevent.duringTime.equals("")) {//单式
					Long eventtime = dfmin.parse(isnevent.eventTime).getTime();
					
					if(eventtime - System.currentTimeMillis() > danshiMaxTime*60*1000 || eventtime - System.currentTimeMillis() < danshiMinTime*60*1000) {
						return false;
					}
					
					return true;
				}else {
					
					int currentmin = 0;
							
					if(isnevent.duringTime.contains("半场")) {
						currentmin = 45;
					}else if(isnevent.duringTime.contains("1H")) {
						String str = isnevent.duringTime.replace("1H", "");
						str = str.replace(" ", "");
						currentmin = Integer.parseInt(str.split(":")[0]);
					}
					
					if(currentmin > gqHalfMaxTime || currentmin < gqHalfMinTime) {
						return false;
					}
							
					return true;
				}
			}
			
			
		
		}catch(Exception e) {
			e.printStackTrace();
		}
		
		
		return false;
		
	}
	
	
	
}
